<?php

namespace App\Model;

use App\Common\Model\ShopAccount;
use Illuminate\Database\Eloquent\Model;

class Order extends Model{

    protected $table = 'order';
    public $timestamps = false;
//    protected  $timestamps = false;
    private $orderInfo = 'order_info';


    public function OrderDetail($like=null,$page,$status=null,$id=null){
        if(!empty($id)){
            $data = $this::where($this->getTable().'.id','=',$id);
        }else{
            $data = $this::where(function($query)use($like){
                if(!empty($like)){
                    $query->where($this->getTable().".order_no",'like',"%$like%")
                        ->orWhere($this->getTable().'.area','like',"%$like%")
                        ->orWhere($this->getTable().'.address','like',"%$like%")
                        ->orWhere($this->getTable().'.receiver','like',"%$like%")
                        ->orWhere($this->getTable().'.send_no','like',"%$like%");
                }
            })->where(function($query)use($status){
                if($status!=-1){
                    $query->where($this->getTable().'.send_status','=',$status);
                }
            });
        }
           $data = $data ->orderBy($this->getTable().'.create_time','desc')
            ->leftjoin($this->orderInfo,$this->orderInfo.'.order_id','=',$this->getTable().'.id')
            ->paginate($page);
        return $data;
    }

}